﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ////生成0 - 5之间的随机小数，保留两位小数（必须是2位）。 
            //Random ran = new Random();
            //Console.WriteLine("生成0 - 5之间的随机小数，保留两位小数:");
            //Console.WriteLine((ran.NextDouble() * 5).ToString("f2"));

            ////生成4 - 7之间的随机小数，保留两位小数。
            //Console.WriteLine();
            //Console.WriteLine("生成4 - 7之间的随机小数，保留两位小数:");
            //Console.WriteLine((4 + ran.NextDouble() * 3).ToString("f2"));

            Random ra = new Random();
            int[] arr = new int[10];
            int tmp = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                tmp = ra.Next(1, 11);
                arr[i] = getNum(arr, ref tmp, ra);
            }
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }

        }

        //生成一个随机整型数组，长度是10，内容是1 ~10，数组内容不重复。
        private static int getNum(int[] arr, ref int tmp, Random ra)
        {
            int n = 0;
            while (n<=arr.Length-1)
            {
                if (arr[n]==tmp)
                {
                    tmp = ra.Next(1, 11);
                    getNum(arr, ref tmp, ra);
                }
                n++;
            }
            return tmp;
        }
    }
}
